package hu.mapro.gwtui.gxt.client.columnmodel;

import hu.mapro.gwtui.gxt.client.columnmodel.field.ReadOnlyAdapter;
import hu.mapro.model.Getter;
import hu.mapro.model.meta.Field;
import hu.mapro.model.meta.HasLabel;

import com.sencha.gxt.widget.core.client.grid.ColumnModel;

public class ColumnModelBuilder<T, F extends Field<T, ?> & HasLabel & Getter<T, ?>>
		extends AbstractColumnModelProvider<T> {

	private F[] tableColumns;

	protected hu.mapro.gwtui.gxt.client.columnmodel.ColumnModelProvider<T> buildColumnModelBuilder() {
		hu.mapro.gwtui.gxt.client.columnmodel.Builder<T, F, Void> builder = new hu.mapro.gwtui.gxt.client.columnmodel.Builder<T, F, Void>(
				buildColumnReadOnly(), null);
		builder.readOnly(tableColumns);
		return builder;
	}

	private ReadOnlyInterface<T, F> buildColumnReadOnly() {
		return new ReadOnlyAdapter<T, F>();
	}

	@Override
	protected ColumnModel<T> buildColumnModel() {
		return buildColumnModelBuilder().asColumnModel();
	}

	public void setTableColumns(F[] tableColumns) {
		this.tableColumns = tableColumns;
	}

}
